#delimit ;
set more off;

/*NOTE: For a Mac, file path names use a forward slash (/) but for 
PC's they require a backward slash (\). Make these changes below 
if necessary depending on your computer type. 
*/

*Dropbox paths by user;
if c(username)=="shayaksarkar" {;
	local path "/Users/shayaksarkar/Desktop/ReStat_Data_Publication";
};


/*TABLE 1*/;

cd `path';

use "`path'/dta/final_competition.dta", clear;

	mat t=J(50,5,.);

	cap program drop panela;
	program define panela;
		syntax [if], line(real);

		count `if';
		mat t[`line',1]=r(N);

		qui tab ms_id `if';
		mat t[`line',2]=r(r);

		qui tab agent_id `if';
		mat t[`line',3]=r(r);
		
		qui sum anyterm `if';
		mat t[`line',4]=r(mean);
		
		qui sum anyulip `if';
		mat t[`line',5]=r(mean);
	

	end;
	
** PANEL A QUALITY OF ADVICE;
use "`path'/dta/final_competition.dta", clear;

	local i=1;
	disp "i is `i'";
	panela if needterm&biasterm&comp, line(`i++');
	panela if needterm&biasterm&comp==0, line(`i++');
	panela if needterm&biaswhole&comp, line(`i++');
	panela if needterm&biaswhole&comp==0, line(`i++');

	panela if needwhole&biasterm&comp, line(`i++');
	panela if needwhole&biasterm&comp==0, line(`i++');
	panela if needwhole&biaswhole&comp, line(`i++');
	panela if needwhole&biaswhole&comp==0, line(`i++');

	count;
	mat t[10,1]=r(N);

	qui tab agent_id;

	mat t[10,3]=r(r);

** PANEL B DISCLOSURE EXPERIMENT;

	clear;
	use "`path'/dta/final_disclosure.dta", clear;
	local i=13;
	
	panela if disclosureknowledge & post==0, line(`i++');
	panela if disclosureknowledge & post==1, line(`i++');
	panela if disclosureknowledge==0 & post==0, line(`i++');
	panela if disclosureknowledge==0 & post==1, line(`i++');
	
	count if disclosureknowledge!=.;
	mat t[`++i',1]=r(N);

	qui tab agent_id if disclosureknowledge!=.;

	mat t[`i',3]=r(r);


** PANEL C SOPHISTICATION EXPERIMENT;
	
	
	clear;
	
	use "`path'/dta/final_sophistication.dta", clear;
	
	local i=21;
	
	panela if sophisticated==0, line(`i++');
	panela if sophisticated==1, line(`i++');
	
	count if sophisticated!=.;
	mat t[`++i',1]=r(N);

	qui tab agent_id if sophisticated!=.;

	mat t[`i',3]=r(r);

	svmat t;
	
	
	outsheet t1-t5 if _n<40 using "`path'/out/table1.csv", comma replace;
	
